'''
Created on 19 dec. 2011

@author: Daan
'''
from random import Random

class Car(object):
    '''
    classdocs
    '''
    def __init__(self, lane = 1, bmap = None, speed=0, maxSpeed=100, accel=10, decel=15, pos=10):
        '''
        Constructor
        '''
        self._uiObj = None
        self._lane = lane
        self._bmap = bmap
        
        self._speed = speed
        self._maxSpeed = maxSpeed
        self._accel = accel
        self._decel = decel
        
        self._pos = bmap._laneLength[lane-1].GetPartOffset(Random().randint(0,3) % 4) if not None == bmap else 0
#        self._pos = pos
        
    def Update(self, tick):
        passed = tick.GetPassedTime()
        if self._speed < self._maxSpeed:
            self._speed += (passed * self._accel)
        
        pos = self._pos + (self._speed * passed)
        self.SetPos(self._bmap.DrawCar(self._lane, pos, self))
    
    def SetPos(self, pos):
        self._pos = pos
        
    def SetUIObj(self, car):
        self._uiObj = car
        return car
    
    def GetUIObj(self):
        return self._uiObj
    
    def hasUIObj(self):
        return not (self._uiObj == None)
